package com.pth.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.struts2.ServletActionContext;

public class FileUtils {

@SuppressWarnings("deprecation")
public static void fileUpload(File filename,String filenameFileName,String filenameContentType,String savepath) {
		
		String root=ServletActionContext.getRequest().getRealPath(savepath);
		try{
		InputStream is=new FileInputStream(filename);
		File destFile=new File(root,filenameFileName);
		OutputStream os=new FileOutputStream(destFile);
		byte [] buffer=new byte[400];
		int length=0;
		while(-1!=(length=is.read(buffer))){
			os.write(buffer, 0, length);
			
		}
		
		is.close();
		os.close();
		}
		catch(IOException e){
			e.printStackTrace();
		}
		
		
		
		
		
		
	}

	

@SuppressWarnings("deprecation")
public static void fileUploadforare(File filename,String filenameFileName,String filenameContentType,String root) {
		
		//String root=ServletActionContext.getRequest().getRealPath(savepath);
		try{
		InputStream is=new FileInputStream(filename);
		File destFile=new File(root,filenameFileName);
		OutputStream os=new FileOutputStream(destFile);
		byte [] buffer=new byte[400];
		int length=0;
		while(-1!=(length=is.read(buffer))){
			os.write(buffer, 0, length);
			
		}
		
		is.close();
		os.close();
		}
		catch(IOException e){
			e.printStackTrace();
		}
		
		
		
		
		
		
	}



	
}
